package com.qys.livesMall.system.service.impl;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qys.livesMall.system.mapper.H2ExchangeRateMapper;
import com.qys.livesMall.system.model.dto.app.ExchangeRateQuery;
import com.qys.livesMall.system.model.entity.H2ExchangeRate;
import com.qys.livesMall.system.service.IH2ExchangeRateService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author caoz
 * @since 2023-04-26
 */
@Service
public class H2ExchangeRateServiceImpl extends ServiceImpl<H2ExchangeRateMapper, H2ExchangeRate> implements IH2ExchangeRateService {

    @Override
    public int add(H2ExchangeRate params) {
        params.setCreateTime(LocalDateTime.now());
        params.setUpdateTime(LocalDateTime.now());
        //生成key
        save(params);
        return 1;
    }

    @Override
    public int put(H2ExchangeRate params) {
        Assert.notNull(params.getId(), "id不能为空！");
        params.setUpdateTime(LocalDateTime.now());
        updateById(params);
        return 1;
    }

    @Override
    public Page<?> pageList(ExchangeRateQuery query) {
        return baseMapper.pageList(new Page<>(query.getPageNum(), query.getPageSize()), query);
    }
}
